﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Royaumes_Libres.Database;

namespace Royaumes_Libres
{
    public partial class login : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            this.lblErrorLogin.Visible = false;

            if (Session[Properties.Settings.Default.ObjUser] != null)
            {
                Response.Redirect("kingdoms.aspx");
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string Username = this.txtUsername.Text;
            string Password = this.txtPassword.Text;
            cUsers User = cUsers.GetUser(Username, Password);

            if (User != null)
            {
                if (User.Active == true)
                {
                    this.Session.Add(Properties.Settings.Default.ObjUser, User);
                    if (User.Admin)
                    {
                        Response.Redirect("adminworld.aspx");
                    }
                    else
                    {
                        Response.Redirect("kingdoms.aspx");
                    }
                }
                else
                {
                    this.lblErrorLogin.Text = cText.GetText("ErrorLoginAct");
                    this.lblErrorLogin.Visible = true;
                }
            }
            else {
                this.lblErrorLogin.Text = cText.GetText("ErrorLogin");
                this.lblErrorLogin.Visible = true;
            }
        }
    }
}